package com.zy.web.controller.system;

import com.zy.framework.web.base.BaseController;
import com.zy.framework.web.page.TableDataInfo;
import com.zy.system.domain.SysUser;
import com.zy.system.service.ISysPostService;
import com.zy.system.service.ISysRoleService;
import com.zy.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @program: zhengyang
 * @author: LuoXin
 * @create: 2018-12-24 13:07
 * @description:
 */
@Controller
@RequestMapping("/system/user")
public class SysUserController extends BaseController
{
    private String prefix = "system/user";


    @Autowired
    private ISysUserService userService;

    @Autowired
    private ISysRoleService roleService;

    @Autowired
    private ISysPostService postService;

    @RequiresPermissions("system:user:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    @RequiresPermissions("system:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysUser user)
    {
        startPage();
        List<SysUser> list = userService.selectUserList(user);
        return getDataTable(list);
    }

    /**
     * 新增用户
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        modelMap.put("roles", roleService.selectRoleAll());
        modelMap.put("posts", postService.selectPostAll());
        return prefix + "/add";
    }

    /**
     * 校验用户名
     *
     * @param user
     * @return
     */
    public String checkLoginNameUnique(SysUser user)
    {
        return "";
    }

    /**
     * 校验手机号
     *
     * @param user
     * @return
     */
    public String checkPhoneUnique(SysUser user)
    {
        return "";
    }

    /**
     * 校验邮箱
     * @param user
     * @return
     */
    public String checkEmailUnique(SysUser user)
    {
        return "";
    }


}
